package com.example.base.mvvm

import androidx.lifecycle.ViewModel
import com.example.base.net.ApiServer
import com.example.base.net.RetrofitUtils
import com.google.gson.Gson
import okhttp3.MediaType.Companion.toMediaTypeOrNull
import okhttp3.RequestBody

open class BaseViewModel:ViewModel() {
    protected val apiServer = RetrofitUtils.getRetrofit().create(ApiServer::class.java)
    //工具类--将map转化成requestbody
    fun mapToBody(map: Map<String,Any>):RequestBody{
        val json = Gson().toJson(map)
        val body = RequestBody.create("application/json;charset=utf-8".toMediaTypeOrNull(),json)
        return body
    }
}